<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>SceneSupport</title>
    <link
      rel="shortcut icon"
      type="image/x-icon"
      href="/examples/public/favicon.ico"
    />
    <link rel="stylesheet" href="../css/common.css" />
  </head>

  <style></style>

  <body>
    <div id="app"></div>
    <div id="button-position">
      <div id="button-group">
        <p>change scene:</p>
        <button id="scene1">scene1</button>
        <button id="scene2">scene2</button>
      </div>
    </div>

    <script type="module">
      import * as THREE from "three";
      import * as Vis from "../../dist/Vis.es.js";
      import { v4 as getUUid } from "uuid";

      const canvasGenerator = new Vis.CanvasGenerator({
        width: 256,
        height: 256,
      })
        .draw((ctx) => {
          ctx.textBaseline = "middle";
          ctx.textAlign = "center";

          ctx.fillStyle = "rgb(206, 42, 230)";

          ctx.font = " bold 68px 微软雅黑";
          ctx.fillText("SCENE", 128, 128);
        })
        .preview();

      const engine = new Vis.ModelingEngineSupport()
        .setDom(document.getElementById("app"))
        .setSize()
        .setStats(true);
      const ambientLight1 = Vis.generateConfig("AmbientLight", {
        intensity: 0.5,
      });

      const ambientLight2 = Vis.generateConfig("AmbientLight", {
        intensity: 1,
      });

      const material = Vis.generateConfig("MeshStandardMaterial");

      const geometry = Vis.generateConfig("BoxGeometry", {
        width: 20,
        height: 20,
        depth: 20,
      });

      const mesh1 = Vis.generateConfig("Mesh", {
        material: material.vid,
        geometry: geometry.vid,
      });

      const scene1 = Vis.generateConfig("Scene", {
        children: [ambientLight1.vid, mesh1.vid],
      });

      const mesh2 = Vis.generateConfig("Mesh", {
        material: material.vid,
        geometry: geometry.vid,
        position: {
          x: 10,
          y: 10,
        },
        scale: {
          x: 2,
          y: 2,
        },
      });

      const scene2 = Vis.generateConfig("Scene", {
        vid: getUUid(),
        children: [ambientLight2.vid, mesh2.vid],
      });

      engine.applyConfig(
        ambientLight1,
        ambientLight2,
        material,
        geometry,
        mesh1,
        scene1,
        mesh2,
        scene2
      );

      engine.setScene(scene1.vid).play();

      document.getElementById("scene1").onclick = () => {
        engine.setScene(scene1.vid);
      };

      document.getElementById("scene2").onclick = () => {
        engine.setScene(scene2.vid);
      };
    </script>
  </body>
</html>
